<script language=JavaScript src='../inv/scripts/innovaeditor.js'></script>
<?

function checkdata($checkall=0)
{
	$err="";
	if (trim($_POST['txtHoten'])=='') $err=$err.'B&#7841;n ch&#432;a nh&#7853;p h&#7885; tên<br>';
		
/*	if (trim($_POST['txtDiachi'])=='') $err=$err.'B&#7841;n ch&#432;a nh&#7853;p &#273;&#7883;a ch&#7881;<br>';
	if ($checkall==0 && $err) return $err;

	if (trim($_POST['txtDienthoai'])=='') $err=$err.'B&#7841;n ch&#432;a nh&#7853;p &#273;i&#7879;n th&#7885;ai<br>';
	if ($checkall==0 && $err) return $err;

	if (trim($_POST['txtEmail'])=='') $err=$err.'B&#7841;n ch&#432;a nh&#7853;p email<br>';
	else if (checkemail(trim($_POST['txtEmail']))==false) $err=$err.'&#272;&#7883;a ch&#7881; email không h&#7907;p l&#7879;<br>';
	*/
	
	return $err;
}

$err="";
$path = "../upload";
$pathdb = "../upload";
if (isset($_POST['butSub'])) {
	$err=checkdata(0);	
	$hoten=trim($_POST['txtHoten']);
	$online=trim($_POST['txtonline']);
	$diachi=trim($_POST['txtDiachi']);
	$status=trim($_POST['ra']);
	$noidung=trim($_POST['txtnoidung']);
	$dienthoai=trim($_POST['txtDienthoai']);
	$email=trim($_POST['txtEmail']);	
	$website=trim($_POST['txtWebsite']);
	$traloi=trim($_POST['traloi']);
	$categories_id=trim($_POST['txtParent']);
	$nn=trim($_POST['nn']);
	$ret=CheckUpload($_FILES["txtImage"],".jpg;.gif;.png;",500*1024,0);
	if ($ret) $err.=$ret."<br>";
	
	if ($err=='')
	{
	
		$fields_arr= array("customers_name" => "'$hoten'","customers_company"=> "'$nn'", "customers_address"=>"'$diachi'","customers_status"=>"'$status'","customers_phone"=>"'$dienthoai'","customers_email"=>"'$email'","customers_website"=>"'$website'","customers_online"=>"' $online'"," categories_id"=>"'$categories_id'","customers_shortdesc"=>"'$traloi'","customers_date_added"=>"SYSDATE()");
		if (!empty($_POST['id'])) {
			$oldid = $_POST['id'];
			$where= "customers_id=".$oldid;
	
			$result = update("customers_mb",$fields_arr,$where);
		}
		else {			
			$result = insert("customers_mb",$fields_arr);
		}

		if($result) {		
			$sqlUpdateField = "";
			if(empty($_POST['id'])) $oldid = mysql_insert_id();
			
			$ext=GetFileExtention($_FILES['txtImage']['name']);
			if (MakeUpload($_FILES['txtImage'],"$path/customer_vip_s$oldid$ext"))
			{
				@chmod("$path/customer_vip_s$oldid$ext", 0777);
				$sqlUpdateField = " customers_image='$pathdb/customer_vip_s$oldid$ext' ";
			}
			
			if($sqlUpdateField)
			{
				$sqlUpdate = "update customers_mb set $sqlUpdateField where customers_id='".$oldid."'";
				mysql_query($sqlUpdate,$con);
			}
			
			$_SESSION['user']=$user;
			echo "<script>window.location='./?act=customers_mb&code=2'</script>";			
		}
		else echo "sai sai sai";
	}
	if ($err=='') echo '<script>window.location="index.php?act=customers_mb&cat='.$_REQUEST['cat'].'&page=$page&code=1"</script>';
  	else echo "<p align=center class='err'>".$err."</p>";
}
?>

<?
	if (isset($_GET['id'])) {
		$oldid=$_GET['id'];
		$page = $_GET['page'];
		$sql = "select * from customers_mb where customers_id='".$oldid."'";
		if ($result = mysql_query($sql,$con)) {
			$row=mysql_fetch_array($result);			
			$hoten=$row['customers_name'];
			$diachi=$row['customers_address'];	
			$dienthoai=$row['customers_phone'];
			$email=$row['customers_email'];	
			$website=$row['customers_website'];
			$nn=$row['customers_company'];
			$image=$row['customers_image'];	
			$status=$row['customers_status'];
			$online=$row['customers_online'];
			$categories_id=$row['categories_id'];
			$traloi=$row['customers_shortdesc'];
						
		}
	}
?><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
<!--
.style2 {color: #FF0000}
-->
</style>
</head>



<div align="center">  
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#0069A8" width="100%" id="AutoNumber1">
  <tr>
    <td width="45%" class="title" align="center" height="20">S&#7917;a / C&#7853;p nh&#7853;t : Kh&#225;ch h&#224;ng VIP</td>
  </tr>
  <tr>
    <td width="45%" >
	          
<TABLE border="0" cellspacing="5" cellpadding="0" width="617" id="table40">
<FORM method="POST" name="registerform" enctype="multipart/form-data" action="index.php">
<input type="hidden" name="act" value="customers_mb_m">
<input type="hidden" name="id" value="<? echo $_REQUEST['id']; ?>">
<TR>
	<TD align="right" class="smallfont" width="156">H&#7885; v&agrave; t&ecirc;n </TD>
	<TD width="22" class="smallfont"><font color="#FF0000">*</font></TD>
	<TD nowrap width="455">
		<font color="#AFAFAF">
		<INPUT class=fieldKey size=33 name=txtHoten value="<? echo $hoten; ?>"></font>	</TD>
</TR>
<!-- <TR>
	<TD align="right" class="smallfont" width="101">Công ty</TD>
	<TD width="15">&nbsp;</TD>
	<TD nowrap width="336">
		<font color="#AFAFAF"><INPUT class=fieldKey size=33 name=txtCongty value="<? echo $congty; ?>"></font>
	</TD>
</TR> -->
<TR>
	<TD align="right" class="smallfont" width="156">E-mail</TD>
	<TD><span class="style2"></span></TD>
	<TD nowrap width="455">
		<font color="#AFAFAF">
		<INPUT class=fieldKey size=33 name=txtEmail value="<? echo $email; ?>"></font>	</TD>
</TR>

<?  if($_GET['act']=='customers_mb_m' && $_GET['id']!=''){?>

<? } else {?>
	  <? }?><TR>
	<TD align="right" class="smallfont" width="156">Ti&ecirc;u &#273;&#7873;:</TD>
	<TD>&nbsp;</TD>
	<TD nowrap width="455">
		<font color="#AFAFAF">
		<INPUT class=fieldKey size=60 name=nn value="<? echo $nn; ?>"></font>	</TD>
</TR>

<TR>
	<TD align="right" class="smallfont" width="156">N&#7897;i dung c&#226;u h&#7887;i:</TD>
	<TD>&nbsp;</TD>
	<TD nowrap width="455">
		<font color="#AFAFAF">
		
		<textarea id="txtonline" name="txtonline" rows=3 cols=60><? echo $online ?></textarea>	</TD>
</TR>

  
<tr>
        <td width="156" class="smallfont" align="right">
        N&#7897;i dung Tr&#7843; lời</td>
        <td width="22" class="smallfont" align="center">&nbsp;        </td>
        <td width="455" class="smallfont">
			
			
			
			
			<textarea id="traloi" name="traloi" rows=7 cols=60><? echo $traloi; ?></textarea>	

			
				</td>
      </tr>
 <tr>
        <td  align="right" class="smallfont" width="156">Tr&#7841;ng th&aacute;i </td>
        <td>&nbsp;        </td>
        <td nowrap width="455"><input name="ra" type="radio" value="1" checked="checked" />
          &#272;&atilde; duy&#7879;t
            <input name="ra" type="radio" value="0" />
          Ch&#432;a duy&#7879;t </td>
      </tr>
<TR>
	<TD colspan="2"> </TD>
	<TD width="455">
		<input type=submit CLASS=button name=butSub value="C&#7853;p nh&#7853;t">
		<input type=reset class="button" name=butReset value="Nh&#7853;p l&#7841;i">	</TD>
  </TR>
<TR>
	<TD colspan="2">&nbsp;</TD>
	<TD>&nbsp;</TD>
</TR>
</FORM>
</table>

</TABLE>

 </td>
  </tr>
  </table>
        </div>